unit uParentesco;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, upai, FMTBcd, DB, DBClient, Provider, SqlExpr, Menus, dxCore,
  dxButton, ExtCtrls, JvExControls, JvLabel, Grids, DBGrids, JvExDBGrids,
  JvDBGrid, StdCtrls, Mask, DBCtrls;

type
  TfParentesco = class(TfPai)
    s_parentesco: TSQLDataSet;
    p_parentesco: TDataSetProvider;
    ds_parentesco: TClientDataSet;
    s_parentescoID_PAR: TIntegerField;
    s_parentescoDESCRICAO: TStringField;
    ds_parentescoID_PAR: TIntegerField;
    ds_parentescoDESCRICAO: TStringField;
    pnl1: TPanel;
    pnl2: TPanel;
    lbl1: TLabel;
    dbedtDESCRICAO: TDBEdit;
    JvDBGrid1: TJvDBGrid;
    JvLabel15: TJvLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnIncluirClick(Sender: TObject);
    procedure btnGravarClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fParentesco: TfParentesco;

implementation

uses UDM;

{$R *.dfm}

procedure TfParentesco.FormCreate(Sender: TObject);
begin
  Incluir := 'S';
  Alterar := 'S';
  Excluir := 'S';
  Cancelar := 'S';
  Procurar := 'S';
  inherited;
  if (not ds_parentesco.Active) then
        ds_parentesco.Open;
end;

procedure TfParentesco.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  if (ds_parentesco.Active) then
        ds_parentesco.Close;
  inherited;

end;

procedure TfParentesco.btnIncluirClick(Sender: TObject);
begin
  inherited;
   dbedtDESCRICAO.SetFocus;
end;

procedure TfParentesco.btnGravarClick(Sender: TObject);
begin
  IF (DtSrc.DataSet.State in [dsInsert]) THEN
  begin
    if dm.c_6_genid.Active then
      dm.c_6_genid.Close;
    dm.c_6_genid.CommandText := 'SELECT CAST(GEN_ID(GEN_PARENTESCO, 1) AS INTEGER) AS CODIGO FROM RDB$DATABASE';
    dm.c_6_genid.Open;
    ds_parentescoID_PAR.AsInteger:=dm.c_6_genidCODIGO.AsInteger;
    dm.c_6_genid.Close;
  end;
  inherited;

end;

end.
